package com.gewu.pm.ui.activity.payment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.gewu.pm.R;
import com.gewu.pm.aop.SingleClick;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.utils.TextStarUtils;
import com.gewu.pm.utils.eventbus.EventBean;
import com.gewu.pm.utils.eventbus.EventBusUtil;
import com.gewu.pm.utils.eventbus.EventCode;
import com.hjq.bar.TitleBar;

/**
 * 新增账期延期单
 */
public final class AddPostponeActivity extends AppActivity {

    private TitleBar mTitleBar;
    private TextView mTerminalNameView;
    private TextView mCurrentDueDateView;
    private TextView mConfirmButton;
    private TextView tvTerminalLabel;

    public static void start(Context context) {
        Intent intent = new Intent(context, AddPostponeActivity.class);
        context.startActivity(intent);
    }
    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_postpone;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mTitleBar = findViewById(R.id.tb_title);
        mTerminalNameView = findViewById(R.id.tv_terminal_name);
        mCurrentDueDateView = findViewById(R.id.tv_current_due_date);
        // ✅ 正确：使用 BottomButton 内部按钮 ID
        mConfirmButton = findViewById(R.id.tv_bottom_button);
        tvTerminalLabel = findViewById(R.id.tv_terminal_label);

        TextStarUtils.setRequiredText(tvTerminalLabel,"终端名称");//给文字加前面的红色星星

        // 设置标题栏
        mTitleBar.setOnTitleBarListener(this);

        // 设置点击事件
        setOnClickListener(mTerminalNameView, mCurrentDueDateView, mConfirmButton);
    }

    @Override
    protected void initData() {
        // 初始化数据
    }

    @SingleClick
    @Override
    public void onClick(android.view.View view) {
        int viewId = view.getId();
        if (viewId == R.id.tv_terminal_name) {
            // TODO: 点击选择终端
            toast("选择终端");
        } else if (viewId == R.id.tv_current_due_date) {
            // TODO: 点击选择日期
            toast("选择日期");
        } else if (viewId == R.id.tv_bottom_button) {
            // 确定按钮
            submitData();
        }
    }

    /**
     * 提交数据
     */
    private void submitData() {
        // 发送 EventBus 通知上一个页面刷新
        EventBusUtil.sendEvent(new EventBean<>(EventCode.PAYMENT_TERM_POSTPONE_ADDED));
        toast("提交成功");
        finish();
    }
}

